; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size      EQU     0x00000100

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size       EQU     0x00000000

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
Heap_Mem        SPACE   Heap_Size



                PRESERVE8
                THUMB

; Vector Table Mapped to Address 0 at Reset
                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors
                EXPORT  __Vectors_End
                EXPORT  __Vectors_Size
                
; Interrupt table
__Vectors       DCD     0x565855AA                 ; Application Head
                DCD     Reset_Handler              ; Reset Handler
__Vectors_End
__Vectors_Size  EQU  (__Vectors_End - __Vectors)


                AREA    |.text|, CODE, READONLY
; Reset handler
Reset_Handler     PROC
                IMPORT  __main
                EXPORT  Reset_Handler
                  
                MOV     R1, SP
                LDR     R0, =__initial_sp
                STR     R1, [R0]
                BL      __main
                
                ENDP
                ALIGN


; User Heap initialization
__user_initial_stackheap     PROC
                EXPORT  __user_initial_stackheap
                  
                LDR     R0, = Heap_Mem
                LDR     R2, = __initial_sp
                LDR     R1, [R2]
                LDR     R2, = (Heap_Mem + Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR
                
                ENDP
                ALIGN

                END
